from mxupy import IM, EntityXControl
import OBEvolutionAI as obe

class MajorControl(EntityXControl):
    class Meta:
        model_class = obe.Major

    def get_list(self, select=None, where=None, order_by=None, group_by=None, having=None, limit=100, offset=None, to_dict=False, recurse=False, backrefs=False, max_depth=1):
        """ 获取专业列表 """
        return super().get_list(select=select, where=where, order_by=order_by, group_by=group_by, having=having, limit=limit, offset=offset, to_dict=to_dict, recurse=recurse, backrefs=backrefs, max_depth=max_depth)
    
    def delete(self, model,recursive=True):
        """ 删除专业 """
        major_id = model.get('majorId') if isinstance(model, dict) else model.majorId
        if major_id == 1:
            return IM().set_error("不能删除默认专业！")
        
        return super().delete(model,recursive)